package com.zmwx.subject.common.entity;

import com.zmwx.subject.common.enums.ResultCode;
import lombok.Data;

@Data
public class Result<T> {
    private  Boolean seucess;// 是否成功
    private int code;// 0:成功，1：失败
    private String message;// 提示信息
    private T data;// 返回数据

    public static Result ok(){
        Result result=new Result();
        result.setSeucess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());

        return result;
    }
    public static<T> Result ok(T data){
        Result result=new Result();
        result.setSeucess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }
    public static<T> Result Fail(){
        Result result=new Result();
        result.setSeucess(false);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(ResultCode.FAIL.getDesc());
        return result;
    }

    public static<T> Result fail(String message) {
        Result result=new Result();
        result.setSeucess(false);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(message);
        return result;
    }
}
